package com.user.web;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.util.AjaxResponse;
import com.user.entity.Manager;
import com.user.service.IManagerService;

@Controller
@RequestMapping("/manager")
public class ManagerController {
	@Autowired
	private IManagerService managerService;
	@RequestMapping("/login")
	public @ResponseBody AjaxResponse login(HttpSession session,Manager manager) {
		try {
			Manager m = managerService.login(manager);
			if(null!=m) {
				session.setAttribute("manager", m);
				return new AjaxResponse(true, "登录成功!");
			}else {
				return new AjaxResponse(false, "用户名或密码错误！");
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return new AjaxResponse(false,"操作失败...");
		}
	}
	@RequestMapping("/logout")
	public void logout(HttpSession session,HttpServletResponse response) {
		try {
			session.removeAttribute("manager");
			response.sendRedirect("/exam/mgr_login");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
}
